# 242.有效的字母异位词
# 给定两个字符串s和t ，编写一个函数来判断t是否是s的字母异位词。
#
# 注意：若s和t中每个字符出现的次数都相同，则称s和t互为字母异位词。
#
# 示例1:
# 输入: s = "anagram", t = "nagaram"
# 输出: true
#
# 示例2:
# 输入: s = "rat", t = "car"
# 输出: false

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        ht1 = {}
        for i in s:
            if i not in ht1:
                ht1[i] = 1
            else:
                ht1[i] += 1
        ht2 = {}
        for i in t:
            if i not in ht2:
                ht2[i] = 1
            else:
                ht2[i] += 1
        if ht1 == ht2:
            return True
        else:
            return False
if __name__ == '__main__':
    s = "anagram"
    t = "nagaram"
    func = Solution()
    res = func.isAnagram(s,t)
    print(res)

#还是用字典更好一点，用列表是要时间长一点
